﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wq.Extensions.Common;
using Wq.Extensions.Repository;
using Wq.MeetingService.Entities;
using Wq.MeetingService.Models;
using Wq.Model;

namespace Wq.MeetingService
{
    public class PrivateRoomService : SqlSugarBaseRepository<PrivateRoomInfo>, IAddSingleton
    {
        /// <summary>
        /// 验证餐厅
        /// </summary>
        /// <param name="model"></param>
        public void Verify(PrivateRoomInfo model)
        {
            if (string.IsNullOrWhiteSpace(model.Name))
                throw new MyException("包厢名称不能为空");
            if (model.VenueId == 0)
                throw new MyException("请选择场地");
            if (model.DiningRommId == 0)
                throw new MyException("请选择餐厅");
            if (model.People <= 0)
                throw new MyException("容纳人数不能为空");
            if (model.Area <= 0)
                throw new MyException("面积不能为空");
            if(model.Id == 0 && base.Count(p => p.DiningRommId == model.DiningRommId) > 50)
                throw new MyException("包厢数量不能超过50个");
        }

        /// <summary>
        /// 修改排序
        /// </summary>
        /// <param name="id"></param>
        /// <param name="sequence"></param>
        public void UpdateSequence(long id, long sequence) => Context.Updateable<PrivateRoomInfo>().SetColumns(p => p.Sequence == sequence).Where(p => p.Id == id).ExecuteCommand();
    }
}
